package dhm.com.dhmshop.updata.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dhm.com.dhmshop.R;
import dhm.com.dhmshop.adapter.mine.SaleDetailAdapter;
import dhm.com.dhmshop.base.BaseActiity;
import dhm.com.dhmshop.base.Presenter.PressenterImpl;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.base.netWork.LoginContract;
import dhm.com.dhmshop.entity.SaleDetailBean;
import dhm.com.dhmshop.utils.SpUtils;

public class SaledetailActivity extends BaseActiity implements LoginContract.IView {

    @BindView(R.id.recy_data)
    RecyclerView recyData;
    @BindView(R.id.typetext)
    TextView typetext;
    @BindView(R.id.statustext)
    TextView statustext;
    private PressenterImpl pressenter;
    private SaleDetailAdapter saleDetailAdapter;
    private String id;

    @Override
    protected int getLayout() {
        return R.layout.activity_saledetail;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        pressenter = new PressenterImpl();
        pressenter.attachView(this);

        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        saleDetailAdapter = new SaleDetailAdapter(this);

        recyData.setLayoutManager(manager);
        recyData.setAdapter(saleDetailAdapter);

        String uid = SpUtils.getString(this, "uid");
        id = getIntent().getStringExtra("id");
        Map<String, String> map = new HashMap<>();
        map.put("token", Constant.TOKEN);
        map.put("uid", uid);
        map.put("id", id);
        pressenter.sendMessage(this, Constant.ServiceDetail, map, SaleDetailBean.class);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void requesta(Object data) {
        if (data instanceof SaleDetailBean) {
            SaleDetailBean saleDetailBean = (SaleDetailBean) data;
            if (saleDetailBean.getCode() == 1) {
                typetext.setText(saleDetailBean.getData().getDetail().getGoodsServiceTypeText());
                statustext.setText(saleDetailBean.getData().getDetail().getStatusText());
                saleDetailAdapter.setShopList(saleDetailBean.getData().getDetail().getGlists());
            }
        }

    }

    @Override
    public void fail(String error) {

    }

    @OnClick({R.id.back, R.id.history})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.history:
                Intent intent = new Intent(this, SalehistoryActivity.class);
                intent.putExtra("id", id);
                startActivity(intent);
                break;
            default:
        }
    }
}
